﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Exp.DAL
Imports Exp.Model
Public Class Resort_service
    Public Function GetAll() As List(Of REM_Resort)
        Dim ctx As New EXPEntities
        Dim list = ctx.REM_Resort.ToList()
        Return list
    End Function
    Public Function GetByID(ByVal iResortID As Integer) As REM_Resort
        Dim ctx As New EXPEntities
        Dim obj = ctx.REM_Resort.Where(Function(o) o.Resort_ID = iResortID).FirstOrDefault()
        Return obj
    End Function
    'Public Function GetByName(ByVal iResortID As Integer) As REM_Resort
    '    Dim ctx As New EXPEntities
    '    Dim obj = ctx.REM_Resort.Where(Function(o) o.Resort_ID = iResortID).FirstOrDefault()
    '    Return obj
    'End Function
    Public Function GetByName(ByVal sName As String) As List(Of REM_Resort)
        Dim ctx As New EXPEntities
        Dim lstObj As New List(Of REM_Resort)
        lstObj = ctx.REM_Resort.Where(Function(o) o.ResortName = sName).ToList()
        Return lstObj
    End Function
    Public Sub Add(objREM_Resort As REM_Resort)
        Dim ctx As New EXPEntities
        ctx.REM_Resort.AddObject(objREM_Resort)
        ctx.SaveChanges()
    End Sub
    Public Sub Delete(ByVal iResortID As Integer)
        Dim ctx As New EXPEntities
        Dim obj = ctx.REM_Resort.Where(Function(o) o.Resort_ID = iResortID).FirstOrDefault()
        ctx.REM_Resort.DeleteObject(obj)
        ctx.SaveChanges()
    End Sub
    Public Sub Edit(objREM_Resort As REM_Resort)
        Dim ctx As New EXPEntities
        Dim obj = ctx.REM_Resort.Where(Function(o) o.Resort_ID = objREM_Resort.Resort_ID).FirstOrDefault()
        obj.ResortName = objREM_Resort.ResortName
        obj.Brand_ID = objREM_Resort.Brand_ID
        obj.isActive = objREM_Resort.isActive
        obj.Country_ID = objREM_Resort.Country_ID
        obj.UpdateDate = objREM_Resort.UpdateDate
        obj.UpdateUser = objREM_Resort.UpdateUser
        obj.Address = objREM_Resort.Address
        obj.Description = objREM_Resort.Description
        ctx.SaveChanges()
    End Sub
    Public Function GetLastID() As Integer
        Dim ctx As New EXPEntities
        Dim iReturn As Integer = 0
        Dim lstObj As New List(Of REM_Resort)
        lstObj = ctx.REM_Resort.ToList()
        lstObj = ctx.REM_Resort.OrderByDescending(Function(p) p.Resort_ID).ToList()
        If Not lstObj Is Nothing Then
            If lstObj.Count > 0 Then
                iReturn = lstObj.Item(0).Resort_ID + 1
            Else
                iReturn = 1
            End If
        End If
        Return iReturn
    End Function
End Class
